package com.czw.ali.register

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.Log
import com.alibaba.ha.adapter.AliHaAdapter
import com.alibaba.ha.adapter.AliHaConfig
import com.alibaba.ha.adapter.Plugin
import com.alibaba.ha.adapter.service.tlog.TLogLevel
import com.alibaba.ha.adapter.service.tlog.TLogService
import com.alibaba.sdk.android.push.CloudPushService
import com.alibaba.sdk.android.push.CommonCallback
import com.alibaba.sdk.android.push.huawei.HuaWeiRegister
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
import com.alibaba.sdk.android.push.register.MeizuRegister
import com.alibaba.sdk.android.push.register.MiPushRegister
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.MetaDataUtils
import com.didi.drouter.annotation.Service
import com.mtzqc.common.BuildConfig
import com.mtzqc.common.app.App
import com.mtzqc.common.init.InitService
import com.mtzqc.common.task.ITask
import com.taobao.monitor.procedure.Header.ttid
import com.taobao.sophix.SophixEntry
import com.taobao.update.adapter.UpdateAdapter
import com.taobao.update.common.Config
import com.taobao.update.common.framework.UpdateRuntime
import com.taobao.update.datasource.UpdateDataSource


@Service(
    function = [InitService::class],
    priority = 60
)
class HaAdapterRegister(
) : InitService {
    override val dependsLib: Array<Class<out ITask>>?
        get() = null
    override val depends: Array<String>?
        get() = null
    override val depName: String
        get() = "HaAdapter"
    override val priority: Int
        get() = 60

    override fun executeInit(app: Application, debug: Boolean, dev: Boolean): Boolean {
        val config = AliHaConfig()
        config.appKey = BuildConfig.EMAS_APP_KEY
        config.appVersion = AppUtils.getAppVersionName()
        config.appSecret = BuildConfig.EMAS_APP_SECRET
        config.channel = App.buildChannel
        config.userNick = null //配置项：用户的昵称
        config.application = app //配置项：应用指针
        config.context = app.applicationContext //配置项：应用上下文
        config.isAliyunos = false //配置项：是否为yunos
        config.rsaPublicKey = BuildConfig.EMAS_TLOG_RSA_PUBLIC_KEY
        //崩溃
        AliHaAdapter.getInstance().addPlugin(Plugin.crashreporter)
        //性能
        AliHaAdapter.getInstance().addPlugin(Plugin.apm)
        //远程日志
        AliHaAdapter.getInstance().addPlugin(Plugin.tlog)
        TLogService.updateLogLevel(TLogLevel.DEBUG) //配置项：控制台可拉取的日志级别
        AliHaAdapter.getInstance().openDebug(debug)
        AliHaAdapter.getInstance().start(config)
        return true
    }
}